/**
 * 
 */
package gui.properties;

import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import java.util.Scanner;

import gui.SLogoGUI;
import gui.properties.groups.AbstractGroup;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;

import model.Model;

import util.reflection.MethodAction;
import util.reflection.Reflection;

import controller.AbstractController;
import controller.PropertiesController;
import controller.SLogoController;

/**
 * @author Shun Fan
 * 
 */
public class Properties extends JPanel
{
	private JTabbedPane myTabPane = new JTabbedPane();
	
	private Model myModel;
	private SLogoController mySLogoController;
	//private ArrayList<AbstractGroup> myGroups = new ArrayList<AbstractGroup>();
	
	private static final String SCANNER_DELIMITTER = ";\\s*";
	
	public Properties(String resourceFile, Model model, SLogoController controller)
	{
		myModel= model;
		mySLogoController = controller;
		try {
			Scanner reader = new Scanner(new File(resourceFile)).useDelimiter(SCANNER_DELIMITTER);
			PropertiesController myController = (PropertiesController) mySLogoController.getControllerFor(reader.next());
			
			while(reader.hasNext()) {
				String tabName = reader.next();
				tabName = "<html><body><table width='50'>" + tabName + "</table></body></html>";
				String className = reader.next();
				String classResource = reader.next();
				//myGroups.add(newGroup);
				myTabPane.addTab( tabName, (Component) Reflection.createInstance(className, classResource, myModel, myController));
			}
		} catch (FileNotFoundException e) {
			System.out.println("File not found - properties contructor");
			e.printStackTrace();
		}		

		add(myTabPane);
	}

	public static void main(String args[]) throws IOException {
		Model model = new Model();
		SLogoController controller = new SLogoController(model);
		Properties p = new Properties("src/resources/properties/PropertyClasses.txt", model, controller);
		JFrame f = new JFrame();
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		p.setBackground(Color.CYAN);
		//f.setLayout(new FlowLayout());
		f.add(p);
		f.setSize(1000,500);
		f.setVisible(true);
	}
}
